1
|
|
|
/** |
2
|
|
|
* @file JS helpers for handling options in ACP. |
3
|
|
|
* |
4
|
|
|
* @author rugk |
5
|
|
|
* @copyright Copyright (c) 2016 rugk |
6
|
|
|
* @license MIT |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
jQuery(document).ready(function() { |
10
|
|
|
'use strict'; |
11
|
|
|
|
12
|
|
|
ReceiveCallback.init(); |
13
|
|
|
}); |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* ReceiveCallback - Handling the option threema_gateway_receivecallback. |
17
|
|
|
* |
18
|
|
|
* @return {object} Methods: update |
19
|
|
|
*/ |
20
|
|
|
var ReceiveCallback = (function () { |
21
|
|
|
'use strict'; |
22
|
|
|
var me = {}; |
23
|
|
|
var $inputElem; |
24
|
|
|
var $hiddenElem; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* getOrgData - Returns the input data of the field the user can see. |
28
|
|
|
* |
29
|
|
|
* @private |
30
|
|
|
* @return {string} |
31
|
|
|
*/ |
32
|
|
|
function getOrgData() { |
33
|
|
|
return $inputElem.text(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* setOrgData - Sets the value of the input field the user can see. |
38
|
|
|
* |
39
|
|
|
* @private |
40
|
|
|
* @param {string} data The data to set. |
41
|
|
|
* @return {string} |
42
|
|
|
*/ |
43
|
|
|
function setOrgData(data) { |
44
|
|
|
if ($inputElem.text() !== data) { |
|
|
|
|
45
|
|
|
return $inputElem.text(data); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* setHiddenData - Change data of the hidden input. |
51
|
|
|
* |
52
|
|
|
* @private |
53
|
|
|
* @param {string} data The data to set. |
54
|
|
|
* @return {string} |
55
|
|
|
*/ |
56
|
|
|
function setHiddenData(data) { |
57
|
|
|
return $hiddenElem.val(data); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* filterData - Filter the input data. |
62
|
|
|
* |
63
|
|
|
* @private |
64
|
|
|
* @param {string} data The data to filter. |
65
|
|
|
* @return {string} |
66
|
|
|
*/ |
67
|
|
|
function filterData(data) { |
68
|
|
|
// remove all bad characters |
69
|
|
|
// https://regex101.com/r/g4Dkb7/1 |
70
|
|
|
return data.replace(/[^\w_-]+/ig, ''); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* init - Initialize handler. |
75
|
|
|
* |
76
|
|
|
*/ |
77
|
|
|
me.init = function init() { |
78
|
|
|
// set variables |
79
|
|
|
$inputElem = $('.threemagw_receivecallback_input'); |
80
|
|
|
$hiddenElem = $('.threemagw_receivecallback_hiddeninput'); |
81
|
|
|
|
82
|
|
|
// register input trigger/event |
83
|
|
|
$inputElem.on('input', me.update); |
84
|
|
|
}; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* update - Update the output field (and, if necessary, also the output |
88
|
|
|
* field) |
89
|
|
|
* |
90
|
|
|
*/ |
91
|
|
|
me.update = function update() { |
92
|
|
|
var data; |
93
|
|
|
|
94
|
|
|
data = filterData(getOrgData()); |
95
|
|
|
setOrgData(data); |
96
|
|
|
setHiddenData(data); |
97
|
|
|
}; |
98
|
|
|
|
99
|
|
|
return me; |
100
|
|
|
})(); |
101
|
|
|
|
This check looks for functions where a
return
statement is found in some execution paths, but not in all.Consider this little piece of code
The function
isBig
will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly returnundefined
.This behaviour may not be what you had intended. In any case, you can add a
return undefined
to the other execution path to make the return value explicit.